# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 14:58
# @Author  : fovegage
# @Email   : fovegage@gmail.com
# @File    : PublicMethod.py
# @Software: PyCharm

# 结构体
# resp = {
#             "ToUserName": xml.get("FromUserName", ""),
#             "FromUserName": xml.get("ToUserName", ""),
#             "CreateTime": int(time.time()),
#             "MsgType": "event",
#             "Content": xml.get("Content", ""),
#         }

import xmltodict

def dicttofiled(dict_xml):
    # 关注
    ret_data = {}
    if "subscribe" == dict_xml.get("Event"):

        ret_data['CreateTime'] = dict_xml.get("CreateTime", "")
        ret_data['FromUserName'] = dict_xml.get('FromUserName', "")
        # 加入数据库
        return ret_data

    # 取消事件
    if "unsubscribe" == dict_xml.get("Event"):
        ret_data['CreateTime'] = dict_xml.get("CreateTime", "")
        ret_data['FromUserName'] = dict_xml.get('FromUserName', "")
        # 数据库用户状态状态0
        return ret_data
